/*NOTICE

This software was produced for the U. S. Government
under Contract No. FA8721-09-C-0002, and is
subject to the Rights in Noncommercial Computer Software
and Noncommercial Computer Software Documentation Clause
(DFARS) 252.227-7014 (JUN 1995)

(c) 2009 The MITRE Corporation. All Rights Reserved.
*/
package org.mitre.xmltransform.spmif;

import org.mitre.xmltransform.XmlInputDocument;
import org.mitre.xmltransform.XmlOutputDocument;
//import org.mitre.xmltransform.uml2tospmif.Uml2InputDocument;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class SynchronizationStep extends HierarchyStep {
	public SynchronizationStep(String pId, String pExecId, Node pNode, XmlInputDocument pInput, XmlOutputDocument pOutput) {
		super(pId, pExecId, pNode, pInput.buildNodeName(pNode, "REF"), pInput, pOutput);
		mProbability = null;
		mPartnerId = null;
		mPartnerName = null;
		mPartnerType = null;
		mPerfScenarioName = null;
		mPerfScenarioFile = null;
		mMyType = null;
	}
	
	public String getIdPrefix() {
		return "SYNCH";
	}
	
	public void setPartner(String pPartnerId, String pPartnerName, String pPartnerType, String pPerfScenarioName, String pPerfScenarioFile) {
		mPartnerId = pPartnerId;
		mPartnerName = pPartnerName;
		mPartnerType = pPartnerType;
		mPerfScenarioName = pPerfScenarioName;
		mPerfScenarioFile = pPerfScenarioFile;
	}
	
	public void setMyType(String pMyType) {
		mMyType = pMyType;
	}
	
	public void setProbability(String pProbability) {
		mProbability = pProbability;
	}
	
	public void addChild(HierarchyStep pChild) {
		throw new IllegalArgumentException("External Reference steps can not have children");
	}

	public void generateStep(Element pParentElement, Device pLocation) {
		//Node node = getNode();
		Element synchNode = mOutput.addElement(pParentElement, "SynchronizationNode", null);
		synchNode.setAttribute("NodeName", getId());
		if (mProbability != null) {
			synchNode.setAttribute("Probability", mProbability);
		}
		if (mMyType == null) throw new IllegalArgumentException("must provide the type of this node (my type).");
		if (mPerfScenarioName == null) throw new IllegalArgumentException("must provide the perf scenario name");
		if (mPerfScenarioFile == null) throw new IllegalArgumentException("must provide the perf scenario file name");
		if (mPartnerName == null) throw new IllegalArgumentException("must provide partner name");
		if (mPartnerType == null) throw new IllegalArgumentException("must provide partner type");
		synchNode.setAttribute("myType", mMyType);
		synchNode.setAttribute("partnerPerfScenarioName", mPerfScenarioName);
		synchNode.setAttribute("partnerPerfFileName", mPerfScenarioFile);
		synchNode.setAttribute("partnerID", mPartnerId);
		synchNode.setAttribute("partnerName", mPartnerName);
		synchNode.setAttribute("partnerType", mPartnerType);
	}

	public String generateArcs(Element pParentElement, String pFromNode) {
		if (getNodeName() == null) return pFromNode;
		if (pFromNode != null) {
			Element arcNode = mOutput.addElement(pParentElement, "Arc", null);
			arcNode.setAttribute("FromNode", pFromNode);
			arcNode.setAttribute("ToNode", getId());
		}
		return getId();
	}
	
	private String mPerfScenarioName, mPerfScenarioFile, mProbability, mPartnerId, mPartnerName, mPartnerType, mMyType;
}